package com.wangkang.eduservice.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangkang.eduservice.entity.EduTeacher;
import com.wangkang.eduservice.mapper.EduTeacherMapper;
import com.wangkang.eduservice.service.EduTeacherService;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author wangkang
 * @since 2022-03-11
 */
//用this或baseMapper来调用底层已定义好的方法，但仅能用baseMapper调用自己定义的方法。
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    /**
     * C端讲师分页查询
     *
     * @param teacherPage 分页对象
     * @return 分页结果集
     */
    @Override
    public Map<String,Object> getTeacherFrontList(Page<EduTeacher> teacherPage) {

        LambdaQueryWrapper<EduTeacher> teacherQuery = new LambdaQueryWrapper<>();
        //根据teacher表中的id字段，作为降序条件，通过page方法去查询出EduTeacher讲师对象。
        teacherQuery.orderByDesc(EduTeacher::getId);

        //把分页数据封装到teacherPage对象
        //teacherPage = (Page<EduTeacher>) this.page(teacherPage,teacherQuery);
        baseMapper.selectPage(teacherPage,teacherQuery);
        //数据列表
        List<EduTeacher>  records=teacherPage.getRecords();
        //当前页码
        long current=teacherPage.getCurrent();
        //总页数
        long pages=teacherPage.getPages();
        //每页容量
        long size=teacherPage.getSize();
        //总记录数
        long total=teacherPage.getTotal();
        //下一页
        boolean hasNext=teacherPage.hasNext();
        //上一页
        boolean hasPrevious=teacherPage.hasPrevious();


        //把分页数据获取出来，放到map集合
        Map<String,Object> map=new HashMap<>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return map;


        //return teacherPage;
    }
}